package com.bianguo.android.functiondemo.model;

import com.bianguo.android.functiondemo.bean.BaseEntity;
import com.bianguo.android.functiondemo.bean.UserBean;
import com.bianguo.android.functiondemo.retrofit.BaseSubscribe;

import java.util.ArrayList;
import java.util.HashMap;

import okhttp3.ResponseBody;

public class ReptileModel extends BaseModel {

    public void getWebServletDemoData(int page, BaseSubscribe<ResponseBody> subscribe) {
        doSubscribe(mFactory.apiService.getWebServletDemoData(page), subscribe);
    }

    public void login(String username, String password, BaseSubscribe<BaseEntity<UserBean>> subscribe) {
        doSubscribe(mFactory.apiService.login(username, password), subscribe);
    }

    public void register(String phoneNumber, String password, BaseSubscribe<BaseEntity<UserBean>> subscribe) {
        doSubscribe(mFactory.apiService.register(phoneNumber, password), subscribe);
    }

    public void saveUser(String name, BaseSubscribe<BaseEntity<UserBean>> subscribe) {
        HashMap<String, String> params = new HashMap<>();
        params.put("name", name);
        doSubscribe(mFactory.apiService.saveUser(params), subscribe);
    }

    public void getUsers(BaseSubscribe<BaseEntity<ArrayList<UserBean>>> subscribe) {
        doSubscribe(mFactory.apiService.getUsers(), subscribe);
    }

    public void getUserById(Integer id, BaseSubscribe<BaseEntity<UserBean>> subscribe) {
        HashMap<String, Integer> params = new HashMap<>();
        params.put("id", id);
        doSubscribe(mFactory.apiService.getUserById(params), subscribe);
    }
}
